package nc.tb.app.desktop.ui.button;

import nc.tb.app.CommonPlan;
import nc.tb.app.desktop.ui.PlanUI;
import nc.tb.pub.NtbFormula;
import nc.tb.pub.services.UtilServiceGetter;
import nc.tb.pub.ui.UIControlCTL;
import nc.tb.pub.util.ProductConfig;
import nc.ui.pub.ClientEnvironment;
import nc.vo.pub.lang.UFDateTime;

public class PlanButton_CalculateExe extends PlanButton_Calculate {

	public PlanButton_CalculateExe(PlanUI ui) {
		super(ui);
	}
	
	public void execAction() throws Exception {
		super.execAction();
		if (!ui.hasSelectPlan())
			return;
		CommonPlan[] plans = null;
		if (table != null) {
			plans = new CommonPlan[]{(CommonPlan)table.getPlan()};
		}
		else if (ui.getStatus() == UIControlCTL.INIT) {
			 plans = ui.getSelectedPlan();
		}
		if (plans != null) {
			UFDateTime lastExecTime = new UFDateTime(System.currentTimeMillis());
			if(ProductConfig.periodSeperatedCotrol()){
				String strServerDate = UtilServiceGetter.getIUtil().getServerDate();
				lastExecTime = new UFDateTime(/*new Date(*/strServerDate);
			}
			String strLastExecutor = ClientEnvironment.getInstance().getUser().getUserName();
			for (int i=0; i<plans.length; i++) {
				plans[i].getPlanInfo().setLast_exectime(lastExecTime);
				plans[i].getPlanInfo().setDescript(strLastExecutor);
			}
		}
	}
	
	protected int getFmlType() {
		return NtbFormula.iExeValCal;
	}
}
